<template>
  <img alt="Vue logo" src="./assets/logo.png">
  <HelloWorld msg="Welcome to Your Vue.js App" />
  <el-dialog title="正在更新新版本,请稍候..." v-model="dialogVisible" width="60%" :close-on-click-modal="closeOnClickModal"
    :close-on-press-escape="closeOnPressEscape" :show-close="showClose" center>
    <div style="width:100%;height:20vh;line-height:20vh;text-align:center">
      <el-progress status="success" :text-inside="true" :stroke-width="20" :percentage="percentage" :width="strokeWidth"
        :show-text="true"></el-progress>
    </div>
  </el-dialog>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import { ipcRenderer } from 'electron';

export default {
  name: 'App',
  data() {
    return {
      // 处理自动更新
      dialogVisible: false,
      closeOnClickModal: false,
      closeOnPressEscape: false,
      showClose: false,
      percentage: 0,
      strokeWidth: 200,
    }
  },
  mounted() {
    let _this = this;
    ipcRenderer.on("message", (event, arg) => {
      if ("update-not-available" == arg.cmd) {
        console.log(arg.message.version);
      }
      if ("update-available" == arg.cmd) {
        //显示升级对话框
        _this.dialogVisible = true;
      } else if ("download-progress" == arg.cmd) {
        let percent = Math.round(parseFloat(arg.message.percent));
        _this.percentage = percent;
      } else if ("error" == arg.cmd) {
        _this.dialogVisible = false;
        _this.$message("更新失败");
      }
      // }
    });
    ipcRenderer.send("checkForUpdate");
  },
  components: {
    HelloWorld
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
